package com.huawei.appgallery.search.ui.card;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.n;
import com.huawei.appgallery.foundation.card.base.bean.KeywordInfo;
import com.huawei.appgallery.foundation.card.base.card.BaseDistCard;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.search.ui.cardbean.SearchRecommendCardBean;
import com.huawei.appgallery.search.ui.widget.HorizontalTextRecyclerView;
import com.huawei.appgallery.search.ui.widget.HorizontalTextRecyclerView.a;
import com.huawei.appmarket.service.exposure.bean.ExposureDetail;
import huawei.widget.HwTextView;
import java.util.ArrayList;
import java.util.List;
import o.ccz;
import o.cdh;
import o.cgz;
import o.chy;
import o.cih;
import o.cuv.b;
import o.cux;
import o.cvl;
import o.ContentManager;
import o.SomeTimerTask;
import o.eiy;
import o.CollectCheck;
import o.MinimumFactory;
import o.evt;

public class SearchRecommendCard extends BaseDistCard {
    private cvl ʻ = null;
    private HwTextView ʼ = null;
    private LinearLayoutManager ʽ = null;
    private int ˊॱ = ccz.ॱ();
    private HorizontalTextRecyclerView ˋ;
    private int ˏॱ;
    private e ॱˊ;
    private long ॱॱ;
    private List<KeywordInfo> ᐝ = null;

    class e extends SomeTimerTask {
        private int ˋ;
        final /* synthetic */ SearchRecommendCard ˎ;

        public e(SearchRecommendCard searchRecommendCard, int i) {
            this.ˎ = searchRecommendCard;
            this.ˋ = i;
        }

        public int[] getVisibleImtePos() {
            int[] iArr = new int[]{-1, -1};
            if (this.ˎ.ʽ != null) {
                try {
                    iArr[0] = this.ˎ.ʽ.ॱˊ();
                    iArr[1] = this.ˎ.ʽ.ʻॱ();
                } catch (Exception e) {
                    cux.ˏ.ˏ("SearchRecommendCard", "findFirstVisibleItemPosition error:" + e.toString());
                }
            }
            return iArr;
        }

        public View ˏ(int i) {
            View view = null;
            if (this.ˎ.ʽ != null) {
                try {
                    view = this.ˎ.ʽ.ˋ(i);
                } catch (Exception e) {
                    cux.ˏ.ˏ("SearchRecommendCard", "getViewByPosition error:" + e.toString());
                }
            }
            return view;
        }

        public List<ExposureDetail> ˏ(int i, int i2) {
            Object obj = evt.ˊ(this.ˎ.ˋ) >= 50 ? 1 : null;
            ArrayList arrayList = new ArrayList();
            if (obj == null) {
                return arrayList;
            }
            ArrayList ˎ = this.ˎ.ˋ(i, i2);
            ExposureDetail exposureDetail = new ExposureDetail();
            exposureDetail.ˎ(ˎ);
            exposureDetail.ॱ(this.ˎ.ˌ().ॱˉ());
            exposureDetail.ˏ(System.currentTimeMillis());
            arrayList.add(exposureDetail);
            return arrayList;
        }

        public long ˊ() {
            return this.ˎ.ॱॱ;
        }

        public int ˋ() {
            return this.ˋ;
        }
    }

    public SearchRecommendCard(Context context) {
        super(context);
    }

    public void ˋ(chy o_chy) {
        if (this.ʻ != null) {
            this.ʻ.ॱ(o_chy, (cih) this);
        }
    }

    public cgz ˏ(View view) {
        ˊ(view);
        new eiy().ˏ(this.ˋ);
        ॱ(this.ˋ);
        ʽ(view);
        this.ˊॱ = cdh.ˎ((Activity) this.ˋ.getContext());
        return this;
    }

    private void ˊ(View view) {
        if (view != null) {
            view.setClickable(true);
            this.ʼ = (HwTextView) view.findViewById(b.ꓸ);
            this.ˋ = (HorizontalTextRecyclerView) view.findViewById(b.ʻˋ);
            this.ʽ = new LinearLayoutManager(view.getContext(), 0, false);
            this.ˋ.setLayoutManager(this.ʽ);
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                this.ˋ.setLayoutDirection(0);
                this.ʽ.ˊ(true);
            }
            this.ʻ = new cvl(this.ᐝ);
            this.ˋ.setAdapter(this.ʻ);
        }
    }

    private void ॱ(HorizontalTextRecyclerView horizontalTextRecyclerView) {
        if (horizontalTextRecyclerView != null) {
            horizontalTextRecyclerView.ॱ(new n(this) {
                final /* synthetic */ SearchRecommendCard ˊ;

                {
                    this.ˊ = r1;
                }

                public void ˎ(RecyclerView recyclerView, int i) {
                    super.ˎ(recyclerView, i);
                    this.ˊ.ˏॱ = i;
                    if (i == 0) {
                        this.ˊ.ॱ(this.ˊ.ˊॱ);
                    }
                }

                public void ˊ(RecyclerView recyclerView, int i, int i2) {
                    super.ˊ(recyclerView, i, i2);
                }
            });
            horizontalTextRecyclerView.setTouchListener(new a(this) {
                final /* synthetic */ SearchRecommendCard ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˊ() {
                    if (1 == this.ˎ.ˏॱ) {
                        this.ˎ.ॱ(this.ˎ.ˊॱ);
                    }
                }
            });
        }
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof SearchRecommendCardBean) {
            SearchRecommendCardBean searchRecommendCardBean = (SearchRecommendCardBean) cardBean;
            this.ᐝ = searchRecommendCardBean.ʽ();
            if (this.ʼ != null) {
                this.ʼ.setText(searchRecommendCardBean.ॱ());
            }
            if (this.ʻ != null) {
                this.ʻ.ˊ(this.ᐝ);
                return;
            }
            return;
        }
        cux.ˏ.ˏ("SearchRecommendCard", "It's not recommend cardBean.");
    }

    public void ॱ(int i) {
        this.ॱॱ = System.currentTimeMillis();
        this.ॱˊ = new e(this, i);
        this.ॱˊ.ˏ();
    }

    private ArrayList<String> ˋ(int i, int i2) {
        if (CollectCheck.isEmpty(this.ᐝ)) {
            return new ArrayList();
        }
        ArrayList<String> arrayList = new ArrayList();
        while (i <= i2 && i < this.ᐝ.size()) {
            CharSequence ˋ = this.ᐝ.get(i) == null ? "" : ((KeywordInfo) this.ᐝ.get(i)).ˋ();
            if (TextUtils.isEmpty(ˋ)) {
                cux.ˏ.ˏ("SearchRecommendCard", "The " + i + " item name is null.");
            } else {
                arrayList.add(ˋ);
            }
            i++;
        }
        return arrayList;
    }
}
